package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;

/**
 * @author liuwei.wen
 *
 */
@Service
public class ArtistDAOImpl {/*

	@Resource
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public Artist getArtistById(Integer Id) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="select Id,User_id,NAME,Store_id,Create_time from artist where Id = ?";
		Artist artist = jdbcTemplate.queryForObject(sql, new Object[] {Id}, new ArtistMapper());
		CustomerContextHolder.clearCustomerType();
		return artist;
	}

	@Override
	public int updateArtist(Artist artist) throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"UPDATE artist SET User_id =? ,NAME =?,Store_id =?, Create_time =? Where Id =?"	
				);
		Object[] params = {artist.getUserId(), artist.getName(), artist.getStoreId(), artist.getCreateTime(),artist.getId()
		};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.update(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public int saveArtist(Artist artist) throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"INSERT INTO artist (User_id,NAME,Store_id,Create_time)VALUES(?,?,?,?)"
				);
		Object[] params = {artist.getUserId(), artist.getName(), artist.getStoreId(), artist.getCreateTime()
		};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret =jdbcTemplate.save(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}
	
	@Override
	public Artist getArtistByUserId(Integer userId) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="select Id,User_id,NAME,Store_id,Create_time from artist where User_id = ?";
		Artist artist = jdbcTemplate.queryForObject(sql, new Object[] {userId}, new ArtistMapper());
		CustomerContextHolder.clearCustomerType();
		return artist;
	}
	

	@Override
	public List<Artist> getArtistByStoreId(int storeId)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="select Id,User_id,NAME,Store_id,Create_time from artist where Store_id = ?";
		List<Artist> list = jdbcTemplate.query(sql, new Object[] {storeId}, new ArtistMapper());
		CustomerContextHolder.clearCustomerType();
		return list;
	}
	
	private static final class ArtistMapper implements RowMapper<Artist> {
		public Artist mapRow(ResultSet rs, int rowNum) throws SQLException {
			Artist artist = new Artist();
			artist.setCreateTime(rs.getTimestamp("Create_time"));
			artist.setId(rs.getInt("Id"));
			artist.setName(rs.getString("NAME"));
			artist.setStoreId(rs.getInt("Store_id"));
			artist.setUserId(rs.getInt("User_id"));
			return artist;
		}
	}
*/


}
